@include('backstage/public/_header')
    <div class="result_wrap">
        <div class="result_title">
            <div class="mark">
                <p>帶<i class="require">*</i>為必填項</p>
            </div>
        </div>
        <form id="form_data">
            {{csrf_field()}}
            <input type="hidden" name="id" value="{{ $gold->id }}" />
            <table class="add_tab">
                <tbody>
                    <tr>
                        <th><i class="require">*</i>分類名稱：</th>
                        <td>
                            <input type="text" class="lg" name="name" maxlength="20" value="{{ $gold->name }}">
                            <p>分類名稱可以寫20個字</p>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>买入价格：</th>
                        <td>
                            <input type="text" name="buy_price" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{{ $gold->buy_price }}">
                            <span><i class="fa fa-exclamation-circle yellow"></i>只能能输入数字和“.”</span>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>卖出价格：</th>
                        <td>
                            <input type="text" name="sale_price" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" value="{{ $gold->sale_price }}">
                            <span><i class="fa fa-exclamation-circle yellow"></i>只能能输入数字和“.”</span>
                        </td>
                    </tr>
                    <tr>
                        <th><i class="require">*</i>类型：</th>
                        <td>
                            <select name="type" >
                                <option>==頂級菜單==</option>
                                @foreach($gold_type as $k=>$v)
                                <option value="{{$k}}" @if($k==$gold->type) selected="selected" @endif>{{$v}}</option>
                                @endforeach
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>排序：</th>
                        <td>
                            <input type="text" onkeyup="value=value.replace(/[^\d{1,}\-\d{1,}|\d{1,}]/g,'')" name="sort_order" maxlength="3" id="sort_order" value="{{ $gold->sort_order }}">
                            <p>只能是數字，數字越大越靠前</p>
                        </td>
                    </tr>
                    <tr>
                        <th>是否显示：</th>
                        <td>
                            <label for=""><input type="radio" value="1" name="is_show" @if($gold->is_show==1) checked="checked" @endif>是</label>
                            <label for=""><input type="radio" value="0" name="is_show" @if($gold->is_show==0) checked="checked" @endif>否</label>
                        </td>
                    </tr>
                </tbody>
            </table>
            <div class="btn_group">
                <input type="button" value="提交" id="btnSub" onclick="onSubmit();">
                <input type="button" class="back" onclick="history.go(-1)" value="返回">
            </div>
        </form>
        <div class="tips">
            <h3>修改產品价格說明</h3>
            <p>1、帶<i class="require">*</i>為必填項，不允許為空</p>
            <p>3、排序：數字越大越靠前</p>
            <p>4、點擊提交 -&gt; 修改价格，返回-&gt; 回到价格控制列表</p>
        </div>
    </div>
    <script type="text/javascript">
        var vfTime = 2;
        var timer=null;
        function setTime(){
            vfTime --;
            if(vfTime<=0){
                vfTime = 0;
                clearInterval(timer);
            }
        }
        function onSubmit(){
            var name = $(":input[name='name']").val();
            var buy_price = $(":input[name='buy_price']").val();
            var sale_price = $(":input[name='sale_price']").val();
            var type = $(":input[name='type']").val();
            if (vfTime!=0 && timer!=null){
                layer.msg('操作過於頻繁', {icon: 7,anim: 6});
                // setTimeout(function(){$("#chiContent").focus();}, 1500);
                return false;
            }
            if (name==''){
                layer.msg('分類名稱不能为空', {icon: 5,anim: 6});
                setTimeout(function(){$(":input[name='name']").focus();},0);
                return false;
            }
            if (buy_price=='') {
                layer.msg('买入价格不能為空', {icon: 5,anim: 6});
                setTimeout(function(){$(":input[name='buy_price']").focus();},0);
                return false;
            }
            if (sale_price=='') {
                layer.msg('卖出价格不能為空', {icon: 5,anim: 6});
                setTimeout(function(){$(":input[name='sale_price']").focus();},0);
                return false;
            }
            var form = new FormData(document.getElementById("form_data"));
//             var req = new XMLHttpRequest();
//             req.open("post", "${pageContext.request.contextPath}/public/testupload", false);
//             req.send(form);
            $.ajax({
                url:"{{$doedit}}",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                dataType : "json",
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.message, {icon: 6});
                        setTimeout(function(){
                            window.location.href=data.jumpUrl;
                        },2000);
                    }else if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }else{
                        layer.msg(data.message, {icon: 5});
                    }
                    
                    clearInterval(timer);
                    timer = setInterval(setTime, 1000, "1");
                    
                },
                error:function(e){
                    layer.msg(e, {icon: 5,anim: 6});
                    clearInterval(timer);
                    timer = setInterval(setTime, 1000, "1");
                }
            });
        }
    </script>
@include('backstage/public/_footer')